public class test2 {
    public static void main(String[] args) {
        //二分查找法
        int[] arr = {7,23,43,78,96,114,157,225};
        System.out.println(binarySerch(arr, 96));
    }
    //定义二分查找方法
    public static int binarySerch(int[] arr,int data){
        int left = 0;
        int right = arr.length -1;
        while (left<=right){
            int midle = (left+right)/2;
            if (data<arr[midle]){
                right = midle -1 ;
            }else if (data > arr[midle]){
                left = midle +1;
            }else {
                return midle;
            }
        }
           return -1;
    }
}
